<!--
 * @Author: Dorange.Wang
 * @Date: 2021-04-07 16:19:40
 * @LastEditors: your name
 * @LastEditTime: 2021-04-12 11:26:27
 * @Description: file content
-->
<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="600px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{ $t("sys.data_retention_days_setting") }}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <el-form class="pl30 pr30" :model="formData" ref="form" label-width="200px">
      <el-form-item
        :label="$t('sys.data_retention_days')"
        prop="days"
        :rules="[
          {
            required: true,
            message: $t('sys.data_retention_days_setting'),
            trigger: 'change',
          },
        ]"
      >
        <el-input-number
          v-model="formData.days"
          :min="1"
          :max="365"
          :step="1"
          step-strictly
          :precision="0"
          style="width: 240px"
          controls-position="right"
        ></el-input-number>
      </el-form-item>
    </el-form>

    <div slot="footer" class="tr">
      <el-button @click="showVisible = false">{{ $t("sys.cancel") }}</el-button>
      <el-button type="primary" @click="submit">{{
        $t("sys.confirm")
      }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      showVisible: false,
      formData: {},
      callback: null
    };
  },

  computed: {},

  methods: {

    open(days = 30,callback) {
      this.formData = { days };
      this.callback = callback;
      this.showVisible = true;
    },

    async submit() {
      try {
        await this.$refs.form.validate();
        const { days } = this.formData;
        if(!this.callback) return
        this.callback(days)
        this.showVisible = false
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
